﻿using UtilPublic.ServerLoger;
using System;
using UtilLib;
using ServerBase.Config;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks;
using ServerBase.Service;
using WebSocketSharp.Server;
using WebSocketSharp;

namespace ServerBase.LunarSocket
{
    /// <summary>
    /// 服务器信息
    /// </summary>
    public static class BaseAppServer
    {

        //AllSessions
        public static ConcurrentDictionary<string, LunarSession> AllSessions = new ConcurrentDictionary<string, LunarSession>();
        public static int SessionCount => AllSessions.Count;



        public static WebSocketServer wssv;
        public static void Setup()
        {
            // 127.0.0.1:8800 ws://127.0.0.1:8800
            // ws://127.0.0.1:8800/Lunar

            wssv = new WebSocketServer(BaseServerInfo.ServerPort);
            wssv.AddWebSocketService<LunarSession>("/Lunar");
            wssv.Start();
        }
        public static bool Start()
        {
            try
            {
                wssv.Start();
            }
            catch (Exception ex)
            {
                loger.Error($"BaseAppServer Start", ex);
                return false;
            }
            return true;
        }

    }

    


}
